﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyChoVayCaNhan.Classes
{
    public abstract class BaseTab
    {
        public const int FILTER_INDEX_DEFAULT = 0;
        // khach hang
        public const int FILTER_INDEX_SEARCH_KH_BY_CMND = 1;


        private System.Windows.Forms.BindingSource _mainBindingDataSource = null;
        public System.Windows.Forms.BindingSource MainBindingDataSource
        {
            get
            {
                return _mainBindingDataSource;
            }
            set
            {
                _mainBindingDataSource = value;
            }
        }
        private int _selectedIndex = -1;
        public int SelectedIndex
        {
            get
            {
                return _selectedIndex;
            }
            set
            {
                _selectedIndex = value;
                if (SelectedIndex == -1)
                {
                    _selectedItem = null;
                }
                else
                {
                    SelectedItem = MainBindingDataSource.Position = SelectedIndex;
                    _selectedItem = MainBindingDataSource.Current;
                }
            }
        }
        private object _selectedItem = null;
        public object SelectedItem
        {
            get { return _selectedItem; }
            set {
                _selectedItem = value;
            }
        }

        private int _filterIndex = 0;

        public int FilterIndex
        {
            get { return _filterIndex; }
            set { _filterIndex = value; }
        }
        private string _filterKey = "";

        public string FilterKey
        {
            get { return _filterKey; }
            set { _filterKey = value; }
        }

        public BaseTab()
        {
            OnCreated();
        }
        public void OnCreated()
        {

        }

        public void CancelEditing()
        {
            MainBindingDataSource.CancelEdit();
        }
        public abstract TabType GetTabType();
        public abstract MenuItemType[] GetSupportedMenus();

        public abstract void LoadData();

        public abstract string GetTabTitle();

        public void SetSelectedIndex(int index)
        {
            SelectedIndex = index;
        }

        public void MenuClick(MenuItemType menuItem)
        {
            switch (menuItem)
            {
                case MenuItemType.ADD:
                    this.OnAddClick();
                    break;
                case MenuItemType.VIEW:
                    this.OnViewClick();
                    break;
                case MenuItemType.EDIT:
                    this.OnEditClick();
                    break;
                case MenuItemType.DELETE:
                    this.OnDeleteClick();
                    break;
                case MenuItemType.REFRESH:
                    this.OnRefreshClick();
                    break;
                case MenuItemType.HELP:
                    this.OnHelpClick();
                    break;
                case MenuItemType.PRINT:
                    this.OnPrintClick();
                    break;
                case MenuItemType.VIEW_TDTD:
                    this.OnViewTDTDClick();
                    break;
                case MenuItemType.VIEW_TTTD:
                    this.OnViewTTTDClick();
                    break;
                case MenuItemType.VIEW_TSDB:
                    this.OnViewTSDBClick();
                    break;
                case MenuItemType.EDIT_TDTD:
                    this.OnEditTDTDClick();
                    break;
                case MenuItemType.EDIT_TTTD:
                    this.OnEditTTTDClick();
                    break;
                case MenuItemType.ADD_TSDB:
                    this.OnAddTSDBClick();
                    break;
                case MenuItemType.PRINT_TDTD:
                    this.OnPrintTDTDClick();
                    break;
                case MenuItemType.PRINT_TTTD:
                    this.OnPrintTTTDClick();
                    break;
                case MenuItemType.PRINT_TSDB:
                    this.OnPrintTSDBClick();
                    break;
                case MenuItemType.SEARCH_KHACH_HANG:
                    this.OnSearchKHClick();
                    break;
                default:
                    break;
            }
        }

        public abstract void OnAddClick();
        public abstract void OnViewClick();
        public abstract void OnEditClick();
        public abstract void OnDeleteClick();
        public abstract void OnHelpClick();
        public abstract void OnPrintClick();
        public abstract void OnRefreshClick();
        public abstract void OnViewTDTDClick();
        public abstract void OnViewTTTDClick();
        public abstract void OnViewTSDBClick();
        public abstract void OnEditTDTDClick();
        public abstract void OnEditTTTDClick();
        public abstract void OnAddTSDBClick();
        public abstract void OnPrintTDTDClick();
        public abstract void OnPrintTTTDClick();
        public abstract void OnPrintTSDBClick();
        public abstract void OnSearchKHClick();
    }
}
